package org.jing.core.logger.logback.filter;

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.filter.AbstractMatcherFilter;
import ch.qos.logback.core.spi.FilterReply;
import org.jing.core.logger.logback.LoggerLevel;

/**
 * Description: 重写LevelFilter, 因为logback糟糕的可扩充性 <br>
 *
 * @author bks <br>
 * @since 2022-11-23 <br>
 */
@SuppressWarnings({ "unused", "WeakerAccess" })
public class LevelFilter extends AbstractMatcherFilter<ILoggingEvent> {
    LoggerLevel level;

    public LevelFilter() {
    }

    public FilterReply decide(ILoggingEvent event) {
        if (!this.isStarted()) {
            return FilterReply.NEUTRAL;
        } else {
            return event.getLevel().levelInt == this.level.getLevel().levelInt ? this.onMatch : this.onMismatch;
        }
    }

    public void setLevel(LoggerLevel level) {
        this.level = level;
    }

    public void start() {
        if (this.level != null) {
            super.start();
        }

    }
}
